﻿namespace CSharpPro.properties._0928;

public class Demo
{
    public void TestPrint()
    {
        int num = 10;
        do
        {
            Console.WriteLine(num);
            num--;
        } while (num>5);

        // while (num > 5)
        //{Console.Write(num+"\t");
        // num--;
        //}
        for (int i = 0; i < 10; i++)
        {
            if (i % 2 != 0)
            {
                Console.Write(i +"");
            }
        }
    }
    
    public void TestPrint2()
    {
        Console.WriteLine("1000以内的水仙花数：");
        for (int num = 100; num < 1000; num++)
        {
            int a = num / 100;
            int b = num / 10 % 10;
            int c = num % 10;
            if (a * a * a + b * b * b + c * c * c == num)
                Console.Write(num + " ");
        }
        Console.WriteLine("\n");
    }
    public void TestPrint3()
    {
        Console.WriteLine("100以内的质数：");
        for (int n = 2; n <= 100; n++)
        {
            bool isPrime = true;
            for (int i = 2; i * i <= n; i++)
            {
                if (n % i == 0) { isPrime = false; break; }
            }
            if (isPrime) Console.Write(n + " ");
        }
        Console.WriteLine();
    }
}